package yyee.llee.mmee.weather.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import yyee.llee.mmee.common.databinding.ItemSettingBinding

/**
 * Created by Lingbaeryi
 */
class SettingAdapter(
    private val context: Context,
    private var names: Array<String>,
    private val onItemClick: (Int) -> Unit,
) :
    RecyclerView.Adapter<SettingAdapter.SettingViewHolder>() {

    class SettingViewHolder(val binding: ItemSettingBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingViewHolder {
        val view = ItemSettingBinding.inflate(LayoutInflater.from(context), parent, false)
        return SettingViewHolder(view)
    }

    override fun getItemCount(): Int {
        return names.size
    }

    override fun onBindViewHolder(holder: SettingViewHolder, position: Int) {
        val title = names[position]
        holder.binding.tvItemTitle.text = title
        holder.binding.rlItem.setOnClickListener {
            onItemClick(position)
        }
    }

}